is this code correct? [closed]

Posted by davit-datuashvili on Stack Overflow See other posts from Stack Overflow or by davit-datuashvili
Published on 2010-05-24T11:26:22Z Indexed on 2010/05/24 11:31 UTC
Read the original article Hit count: 152

Filed under:

hi i have poste this code from this title http://stackoverflow.com/questions/2896363/hi-i-have-question-here-is-pseudo-code-about-sift-up-and-sift-down-on-heaps i have following code of siftup on heap is it correct?i have put here because i have changed at old place my question and it became unreadable so i have posted here

public class siftup{

public  static void main(String[]args){

int p;

int n=12;
int a[]=new int[]{15,20,12,29,23,17,22,35,40,26,51,19};

int i=n-1;
 while (i!=0){

 if (i==1)
 break;

p=i/2;
 if (a[p]<=a[i]){
 int t=a[p];
a[p]=a[i];
a[i]=t;
}
i=p;


}

 for (int j=0;j<n;j++){
 System.out.println(a[j]);
}


}
}

//result is this 15 20 19 29 23 12 22 35 40 26 51 17

is it correct?

© Stack Overflow or respective owner

Related posts about algorithm